package com.example.demo.service;

import org.springframework.stereotype.Service;
import java.util.*;
import com.example.demo.model.AIMessage;

@Service
public class AIChatSessionService {
    // 使用 Map 存储会话，key 是会话ID
    private Map<String, List<AIMessage>> sessions = new HashMap<>();
    
    // 创建新会话
    public String createSession() {
        String sessionId = UUID.randomUUID().toString();
        sessions.put(sessionId, new ArrayList<>());
        return sessionId;
    }
    
    // 添加消息到会话
    public void addMessage(String sessionId, AIMessage message) {
        List<AIMessage> messages = sessions.getOrDefault(sessionId, new ArrayList<>());
        messages.add(message);
        sessions.put(sessionId, messages);
    }
    
    // 获取会话历史
    public List<AIMessage> getHistory(String sessionId) {
        return sessions.getOrDefault(sessionId, new ArrayList<>());
    }
    
    // 清除会话
    public void clearSession(String sessionId) {
        sessions.remove(sessionId);
    }
} 